package com.shangqing.system.hightemperature.service.Impl;

import com.shangqing.system.droughtinformation.entity.City;
import com.shangqing.system.hightemperature.entity.HighTemWarning;
import com.shangqing.system.hightemperature.entity.HighTemperature;
import com.shangqing.system.hightemperature.mapper.HighTemperatureMapper;
import com.shangqing.system.hightemperature.service.IhighTemperatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class HighTemperatureImpl implements IhighTemperatureService {
    @Autowired
    private HighTemperatureMapper highTemperatureMapper;

    @Override
    public List<HighTemperature> getAll() {
        List<HighTemperature> highTemperatureList = new ArrayList<>();
        List<HighTemperature> highTemperatures = highTemperatureMapper.getAllInfo();
        City city=null;
        for (HighTemperature h : highTemperatures
        ) {
            h.setWindWarning(highTemperatureMapper.getHighWarning(h.getHightemperaturewarninglevelid()));
            city = highTemperatureMapper.getAllCity(h.getLocationid());
            city.setCityList(cityVos(city));
            h.setCity(city);
            highTemperatureList.add(h);
        }
        return highTemperatureList;
    }


    /**
     * 递归方法体
     */
    private City cityVos(City city) {
        if (city.getParentId() == 0) {
            return null;
        } else {
            City vo = highTemperatureMapper.getAllCity(city.getParentId());
            City cityVo = new City();
            cityVo.setId(vo.getId());
            cityVo.setCityName(vo.getCityName());
            cityVo.setParentId(vo.getParentId());
            cityVo.setCityList(cityVos(vo));
            return cityVo;
        }
    }

    @Override
    public List<HighTemWarning> getHighWarning() {
        return null;
    }
}
